class Event {
  String name
  String description
  Date startDate
  Date endDate
  String location
  Volunteer owner

  static mapping = {
    cache true
  }

  static hasMany = [positions: EventPosition]

  static constraints = {
    name(blank: false)
    description(blank: false)
    startDate(blank: false)
    endDate(blank: false,
            validator: {
              val, obj ->
              if (val != null) {
                return val.after(obj.startDate)
              }
              return true
            })
    owner(blank: false)
  }

  String toString() {
    name
  }

  boolean equals(o) {
    if (this.is(o)) return true;
    if (!o || getClass() != o.class) return false;

    Event event = (Event) o;

    if (name != event.name) return false;
    if (description != event.description) return false;
    if (startDate != event.startDate) return false;
    if (endDate != event.endDate) return false;
    if (location != event.location) return false;
    if (owner != event.owner) return false;

    return true;
  }

  int hashCode() {
    int result;
    result = (name ? name.hashCode() : 0);
    result = 31 * result + (description ? description.hashCode() : 0);
    result = 31 * result + (startDate ? startDate.hashCode() : 0);
    result = 31 * result + (endDate ? endDate.hashCode() : 0);
    result = 31 * result + (location ? location.hashCode() : 0);
    result = 31 * result + (owner ? owner.hashCode() : 0);
    return result;
  }
}
